﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Command;
using Structure.Objects;
using Structure.Interfaces;

namespace Application.Controls
{
    public partial class UserForm : System.Web.UI.UserControl
    {
        public event Action OnAdd;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void UserFormClose_Click(object sender, ImageClickEventArgs e)
        {
            UserFormDiv.Visible = false;
        }

        protected void addUser_Click(object sender, EventArgs e)
        {
            UserFormDiv.Visible = true;
        }

        protected void btAddUser_Click(object sender, EventArgs e)
        {
            iCommand command = BuildCommand.Build();
            User pUser = null;
            switch (DropDownList1.SelectedIndex)
            {
                case 0:
                    pUser = new Manager(Name.Text, Password.Text, FIO.Text);
                    break;
                case 1:
                    pUser = new Commiter(Name.Text, Password.Text, FIO.Text);
                    break;
                case 2:
                    pUser = new Observer(Name.Text, Password.Text, FIO.Text);
                    break;
            }
            command.AddUser(pUser);

            UserFormDiv.Visible = false;
            OnAdd();
        }

    }
}